/**
 * Created by gaoyj on 2018/6/28.
 */
window.onload = function (ev) {
    topbar.hide();
};
auditGet2();
function auditGet2() {
    $.ajax({
        type: "POST",
        url: "/QbOrderController/getQbChargeStatus",
        success: function (data) {
            if (data) {
                $('#include').bootstrapToggle('on');
            } else {
                $('#include').bootstrapToggle('off');
            }
        },
    });
}
//开启关闭
$('#stopPro').click(function (e) {
    var status;
    e.stopPropagation();
    var remind = "";
    var isOn = $('#include').prop('checked');
    if (isOn) {
        remind = "关闭";
        status = 0
    } else {
        remind = "开启"
        status = 1
    }
    $.confirm({
        title: '确认!',
        content: '确定要' + remind + 'Q币寄售吗？',
        confirm: function () {
            $.ajax({
                type: "POST",
                url: "/QbOrderController/changeQbChargeStatus",
                data: {
                    status: status
                },
                dataType: "json",
                success: function (data) {
                    if (data.success) {
                        layer.msg(data.message);
                        auditGet2();
                    } else {
                        layer.msg(data.message);
                        auditGet2();
                    }
                }
            })
        }
    })
})
auditGet();
function auditGet() {
    $.ajax({
        type: "POST",
        url: "/AlipayConfigController/getAlipayStatus",
        success: function (data) {
            if (data) {
                $('#include2').bootstrapToggle('on');
            } else {
                $('#include2').bootstrapToggle('off');
            }
        },
    });
}
//开启关闭
$('#stopPro2').click(function (e) {
    var status;
    e.stopPropagation();
    var remind = "";
    var isOn = $('#include2').prop('checked');
    if (isOn) {
        remind = "关闭";
        status = 0
    } else {
        remind = "开启"
        status = 1
    }
    $.confirm({
        title: '确认!',
        content: '确定要' + remind + '支付宝提现吗？',
        confirm: function () {
            $.ajax({
                type: "POST",
                url: "/AlipayConfigController/changeAlipayStatus",
                data: {
                    status: status
                },
                dataType: "json",
                success: function (data) {
                    if (data.success) {
                        layer.msg(data.message);
                        auditGet();
                    } else {
                        layer.msg(data.message);
                        auditGet();
                    }
                }
            })
        }
    })
})
$.get("../config/findConfigInfo", null, function (data) {
    if (data == null || data.length == 0) {
        return;
    }
    var str = '';
    for (var i = 0; i < data.length; i++) {
        str += '<dt style="width: 290px">' + data[i].name + '</dt>' +
            '<dd>' +
            '<div class="col-sm-6">' +
            '<div class="input-group " style="width: 100%">' +
            '<input class="form-control" type="text" value="' + data[i].value + '" id="config' + data[i].id + '">';
        str += '<span class="input-group-btn"><button class="btn btn-primary" onclick="toUpdate(this)" type="button" data-field="' + data[i].id + '">提交 </button></span>';
        str += '</div>' +
            '</div>' +
            '</dd>'
    }
    $("#formset").append(str);

});

function toUpdate(obj) {

    var o = $(obj).attr("data-field");

    var value = $("#config" + o).val();
    $.confirm({
        title: '确认!',
        content: '确定提交该设置吗？',
        confirm: function () {
            $.ajax({
                type: "POST",
                url: "/config/updateConfigValue",
                traditional: true,
                data: {
                    configureId: o,
                    value: value
                },
                dataType: "json",
                success: function (data) {
                    if (data.success) {
                        layer.msg(data.message);
                    } else {
                        layer.msg(data.message)
                    }
                },
                beforeSend: function () {
                }
            });
        },
        cancel: function () {

        }

    })
}